﻿using System;
using System.Collections;
using System.Collections.Generic;

namespace LiveGame
{
    public class Neighbor :IEnumerable<Cell>, IDataStructure<Cell>
    {
        internal Neighbor()
        {
            this.neighbors = new List< Cell >();
        }

        private readonly IList< Cell > neighbors; 

        public Cell this[int index]
        {
            get { return this.neighbors[ index ]; }
        }

        public int Length
        {
            get { return this.neighbors.Count; }
        }

        public void Add( Cell neighbor )
        {
            if( this.neighbors.Count >= 8 )
                throw new ArgumentOutOfRangeException( "neighbor" );

            this.neighbors.Add( neighbor );
        }

        public IEnumerator< Cell > GetEnumerator()
        {
            foreach( var cell in neighbors )
                yield return cell;
        }

        IEnumerator IEnumerable.GetEnumerator()
        {
            return GetEnumerator();
        }
    }
}